Current Location: Home> Function Categories> readdir

readdir

Read entries from directory handle
Name:readdir
Category:Directory functions
Programming Language:php
One-line Description:Returns the entry in the directory handle.

Definition and usage

readdir() function returns the file name of the next file in the directory.

Example

Open a directory, read its contents, and close:

 <?php
$dir = "/images/" ;

// Open the directory and read its contents
if ( is_dir ( $dir ) ) {
  if ( $dh = opendir ( $dir ) ) {
    while ( ( $file = readdir ( $dh ) ) !== false ) {
      echo "filename:" . $file . "<br>" ;
    }
    closedir ( $dh ) ;
  }
}
?>

result:

 filename: cat.gif
filename: dog.gif
filename: horse.gif

grammar

 readdir ( dir_handle ) ;
parameter describe
dir_handle

Optional. Specifies the directory handle resource that was previously opened by opendir() .

If this parameter is not specified, the last link opened by opendir() is used.

Similar Functions
Popular Articles